package com.eig.courseweb.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.eig.common.entity.course.EduCourse;
import com.eig.common.vo.Result;
import com.eig.courseweb.dao.CourseShouCangDao;
import com.eig.courseweb.service.CourseShouCangService;
import com.eig.courseweb.utils.IdWorker;
import com.eig.courseweb.vo.ShouCangVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：StudentLsj（李世界）
 * @date ：Created in 2023/01/05 上午 09:31
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class CourseShouCangServiceImpl implements CourseShouCangService {

    @Resource
    private CourseShouCangDao courseShouCangDao;
    @Resource
    private IdWorker id;


    @Override
    public Result findFavoriteCourseById(String huiYuanId) {
        List<EduCourse> courseShouchs = courseShouCangDao.findFavoriteCourseById(huiYuanId);
        if (ObjectUtil.isNotEmpty(courseShouchs)) {
            return new Result(2000, "查询成功", courseShouchs);
        }
        return new Result(5000, "该会员没有收藏得课程");
    }

    @Override
    public Result deleteFavoriteCourse(ShouCangVo s) {
        int i = courseShouCangDao.deleteFavoriteCourse(s);
        if (i > 0) {
            return new Result(2000, "取消成功", i);
        }
        return new Result(5000, "取消失败", i);
    }

    @Override
    public Result findFavoriteCourse(ShouCangVo s) {
        ShouCangVo favoriteCourse = courseShouCangDao.findFavoriteCourse(s);
        Map<String, Object> map = new HashMap<>();
        if (ObjectUtil.isNotEmpty(favoriteCourse)) {
            map.put("status", 1);
            return new Result(2000, "查询成功", map);
        }
        map.put("status", 0);
        return new Result(2000, "查询失败", map);
    }

    @Override
    public Result addFavoritescourse(ShouCangVo s) {
        s.setTeacherid(id.nextId());
        int i = courseShouCangDao.addFavoritescourse(s);
        if (i > 0) {
            return new Result(2000, "操作成功", i);
        }
        return new Result(5000, "操作失败", i);
    }
}
